package com.lzs.Service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lzs.DAO.CertificateDAO;
import com.lzs.PO.Certificate;
import com.lzs.PO.CertificateExcel;
import com.lzs.PO.Member;
import com.lzs.PO.Page;
import com.lzs.Service.CertificateService;


@Service
public class CertificateServiceImpl implements CertificateService {
	@Autowired
	CertificateDAO certificateDAO;

	@Override
	public Page<Certificate> findCertificatePagelist(String rural_id, String keyword, Integer pageSize,
			Integer pageNum) {
		
		List<Certificate> arealist = this.certificateDAO.findCertificatelist(rural_id,keyword);

		int totalRecord = arealist.size();

		Page<Certificate> page = new Page<Certificate>(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(certificateDAO.findCertificatePagelist(rural_id,keyword, startIndex, pageSize));
		
		return page;
	}

	@Override
	public boolean countCertificateByDisease(String disease_name, String rural_id) {
		
		long count = this.certificateDAO.countCertificateByDisease(disease_name,rural_id);
		
		return count==0;
	}

	@Override
	public Member findCertificateWithMemberByRuralId(String rural_id) {
		
		Member member = this.certificateDAO.findCertificateWithMemberByRuralId(rural_id);
		
		return member;
	}

	@Override
	public void addCertificate(Map<String, Object> map) {
		
		this.certificateDAO.addCertificate(map);
		
	}

	@Override
	public Certificate findCertificateWithMemberByCertificateIdAndRuralId(String certificate_id, String rural_id) {
		
		Certificate certificate = this.certificateDAO.findCertificateWithMemberByCertificateIdAndRuralId(certificate_id,rural_id);
		
		return certificate;
	}

	@Override
	public void updateCertificate(Map<String, Object> map) {
		
		this.certificateDAO.updateCertificate(map);
		
	}

	@Override
	public void deleteCertificate(String certificate_id) {
       
		this.certificateDAO.deleteCertificate(certificate_id);
		
	}

	@Override
	public Page<Certificate> findCertificatePagelist4All(String keyword, Integer pageSize, Integer pageNum) {
		
		List<Certificate> arealist = this.certificateDAO.findCertificatelist4All(keyword);

		int totalRecord = arealist.size();

		Page<Certificate> page = new Page<Certificate>(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(certificateDAO.findCertificatePagelist4All(keyword, startIndex, pageSize));
		
		return page;
	}

	@Override
	public List<CertificateExcel> findCertificate4InputExcel(String keyword) {
		
		List<CertificateExcel> list = this.certificateDAO.findCertificate4InputExcel(keyword);
		
		return list;
	}

	@Override
	public boolean countCertificateByRuralId(String rural_id) {
		
		long count = this.certificateDAO.countCertificateByRuralId(rural_id);
		
		return count==0;
	}

	@Override
	public Certificate findCertificateByDiseaseAndRuralId(String disease_name, String rural_id) {
		
		Certificate certificate = this.certificateDAO.findCertificateByDiseaseAndRuralId(disease_name,rural_id);
		return certificate;
	}

}
